package com.cqq.pro.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @author CHENQQ
 * @date 2015-12-17
 */
public class FileFormatFilter {

	private static Map<String,String> IMAGE_FORMATS_MAP=new HashMap<String, String>();
	static{
		IMAGE_FORMATS_MAP.put(".jpg", ".jpg");
		IMAGE_FORMATS_MAP.put(".jpeg", ".jpeg");
		IMAGE_FORMATS_MAP.put(".bmp", ".bmp");
		IMAGE_FORMATS_MAP.put(".png", ".png");
		IMAGE_FORMATS_MAP.put(".gif", ".gif");
		IMAGE_FORMATS_MAP.put(".tiff", ".tiff");
		IMAGE_FORMATS_MAP.put(".swf", ".swf");
		IMAGE_FORMATS_MAP.put(".pcx", ".pcx");
		IMAGE_FORMATS_MAP.put(".tga", ".tga");
		IMAGE_FORMATS_MAP.put(".exif", ".exif");
		IMAGE_FORMATS_MAP.put(".fpx", ".fpx");
		IMAGE_FORMATS_MAP.put(".svg", ".svg");
		IMAGE_FORMATS_MAP.put(".psd", ".psd");
		IMAGE_FORMATS_MAP.put(".cdr", ".cdr");
		IMAGE_FORMATS_MAP.put(".dxf", ".dxf");
		IMAGE_FORMATS_MAP.put(".ufo", ".ufo");
		IMAGE_FORMATS_MAP.put(".eps", ".eps");
		IMAGE_FORMATS_MAP.put(".ai", ".ai");
		IMAGE_FORMATS_MAP.put(".raw", ".raw");
		
	}
	
	public static void setFormatsOfImage(String[] formats){
		if(formats!=null&&formats.length>1){
			for (String format : formats) {
				IMAGE_FORMATS_MAP.put(format, format);
			}
		}
	}
	
	public static String[] getFileNamesAfterFilter(String[] fileNames){
		if(fileNames==null||fileNames.length<1)
			return null;
		List<String> list = new ArrayList<String>();
		for (String fileName : fileNames) {
			if(fileName.lastIndexOf('.')>0){
				String format = fileName.substring(fileName.lastIndexOf('.'));
				if(IMAGE_FORMATS_MAP.containsKey(format)){
					list.add(fileName);
				}
			}
		}
		return list.toArray(new String[]{});
	}
	
/*	public static void main(String[] args) {
		String[] temp = new String[]{"hhahah.jpg","naonag","hoxhh.png"};
		String[] result = getFileNamesAfterFilter(temp);
		for (String t : result) {
			System.out.println(t);
		}
	}*/
	
}
